package com.epam.tcs.dao.hibernate.impl;

import java.util.List;

import org.hibernate.Session;

import com.epam.tcs.dao.factory.JournalLectureStatusDAO;
import com.epam.tcs.dao.hibernate.ConnectionFactory;
import com.epam.tcs.dao.hibernate.entities.JournalLectureStatus;

public class JournalLectureStatusDAOHibernateImpl extends
		ElementDAOHibernateImpl<JournalLectureStatus> implements
		JournalLectureStatusDAO {

	public JournalLectureStatusDAOHibernateImpl(Class objType) {
		this.objType = objType;
	}

	@Override
	public JournalLectureStatus getElement(long id) {
		Session session = ConnectionFactory.getOrInitSession();
		JournalLectureStatus journalLectureStatus = (JournalLectureStatus) session
				.load(objType, id);

		journalLectureStatus.getLecture();
		journalLectureStatus.getLectureStatus();
		journalLectureStatus.getStudent();

		session.close();
		return journalLectureStatus;
	}

	@Override
	public List<JournalLectureStatus> getAllElements() {
		Session session = ConnectionFactory.getOrInitSession();
		List<JournalLectureStatus> journalLectureStatuses = (List<JournalLectureStatus>) session
				.createQuery("from " + objType.getName()).list();

		for (JournalLectureStatus journalLectureStatus : journalLectureStatuses) {
			journalLectureStatus.getLecture();
			journalLectureStatus.getLectureStatus();
			journalLectureStatus.getStudent();

		}
		
		session.close();
		return journalLectureStatuses;
	}

}
